// 菜单相关
import { getUserMenu } from "@/api/sys/menu";

export default {
    // state 状态
    state: {
        isAddRoute: false, // 是否添加动态路由
        menuList: [] // 路由菜单
    },
    getters: {

    },
    mutations: {
        SET_IS_ADD_ROUTE(state, isAddRoute) {
            state.isAddRoute = isAddRoute;
        },
        SET_MENU_LIST(state, menuList) {
            state.menuList = menuList;
        }
    },
    actions: {
        getUserMenu({ commit }, username) {
            // 获取当前登录用户的权限菜单
            return new Promise(((resolve, reject) => {
                // 获取当前用户账号
                getUserMenu(username).then(resp => {
                    commit('SET_MENU_LIST', resp.data);
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            }));
        }
    }
}